using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Entity.Infrastructure;
using ShopPowerTemplate.Services.Properties;
using ShopPowerTemplate.Entities;

namespace ShopPowerTemplate.Services
{
    public class OrderService : OrderServiceBase, IOrderService
    {
		public OrderService(IEntitiesDB entitiesDB) : base(entitiesDB) { }

        //Custom code here
        public override Int32 Add(Order order)
        {
            order.Customer = EntitiesDB.EntryWithState(order.Customer, EntityState.Unchanged);
            order.OrderState = EntitiesDB.EntryWithState(order.OrderState, EntityState.Unchanged);

            foreach (OrderDetail orderDetail in order.OrderDetails)
                orderDetail.ProductDetail = EntitiesDB.EntryWithState(orderDetail.ProductDetail, EntityState.Unchanged);

            EntitiesDB.OrderSet.Add(order);
            EntitiesDB.SaveChanges();
            return order.Id;
        }
    }
}	

